<?php 
## include required files
/*******************************/
require_once '../model/paypal.php';
require_once '../model/moduleuser.php';
## Paginaton class
require_once ("../includes/classes/pagination_class.php");
/*******************************/

## Create Objects
/*******************************/
$paypalObj   = new Model_Paypal();
$moduleObj = new Model_ModuleUser();
/*******************************/

## Get id from the url 
if($_GET['id']!='') {
	$id  = base64_decode($_GET['id']);
}

$res = $paypalObj->getDetailsFromPaypalById($id);
//echo "<pre>";print_r($res);exit;
$smarty->assign('payPalArray', $res[0]);


if(!empty($_POST)){
	if(isset($_POST['update'])){
		
		if(trim($_POST['merchant_live'])!='' && trim($_POST['merchant_sandbox'])!=''){
			$updatePaypalArray = array();
			$updatePaypalArray['merchant_live']     = trim($_POST['merchant_live']);
			$updatePaypalArray['merchant_sandbox']    = trim($_POST['merchant_sandbox']);
			$updatePaypalArray['mode'] = trim($_POST['mode']);
			$updatePaypalArray['url_live'] = trim($_POST['url_live']);
			$updatePaypalArray['url_sandbox'] = trim($_POST['url_sandbox']);
			$updatePaypalArray['published'] = trim($_POST['published']);
			
			$paypalObj->UpdatePayPalDetails($updatePaypalArray,$id);
			$_SESSION['msg']='<div class="success_msg"> <span> Paypal setting has been updated successfully!</span></div>';
			@header("location:".SITE_URL."/admin/home.php?q=paypal");
			exit;			
		}else{
				$_SESSION['msg']='<div class="error_msg"> <span> Please fill up all the details.</span></div>';
		}
	
	}
}
## Assign session message to smarty variable and unset session variable
if($_SESSION['msg'] != '') {
	$smarty->assign('msg', $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

## Set active class variable for left menu (main menu and sub menu)
$smarty->assign('activeclass', 'paypal');
$smarty->assign('mainmenu', '5');

## Unset all the objects created which are on this page
unset($paypalObj);
unset($moduleObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'paypal/editpaypal.tpl');
unset($smarty);
?>